//
//  Account.m
//  playlive_sdk
//
//  Created by psvn047 on 5/14/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AccountService.h"
@implementation AccountService
-(void) signIn: (NSString*) serviceId emailAddress:(NSString*) emailAddress password:(NSString*) password
{
    NSMutableDictionary * query = [NSMutableDictionary dictionary];
    [query setObject:password forKey:@"password"];
    [query setObject:emailAddress forKey:@"email_address"];
    
    
    [self callService:serviceId httpMethod:@"POST" httpHost:[self getHTTPHost] path:@"session" queryParameters:query messageBody:NULL application:[self getApplication] session:NULL];
}

-(void) signUp: (NSString*) serviceId fullName:(NSString*) fName emailAddress:(NSString*) eAddress password:(NSString*) pword recaptchaPrivateKey: (NSString*) rPrivateKey recaptchaChallenge:(NSString*) rChallenge recaptchaResponse:(NSString*) rResponse
{
    NSMutableDictionary * query = [NSMutableDictionary dictionary];
    [query setObject:fName forKey:@"fullname"];
    [query setObject:eAddress forKey:@"email_address"];
    [query setObject:pword forKey:@"password"];
    NSMutableDictionary * recaptcha = [NSMutableDictionary dictionary];
    
    [recaptcha setObject:rPrivateKey forKey:@"private_key"];
    [recaptcha setObject:rChallenge forKey:@"challenge"];
    [recaptcha setObject:rResponse forKey:@"response"];
    
    [query setObject:recaptcha forKey:@"recaptcha"];
    
    [self callService:serviceId httpMethod:@"POST" httpHost:[self getHTTPHost] path:@"account" queryParameters:query messageBody:NULL application:[self getApplication] session:NULL];
}

-(void) signOut:(NSString*) serviceId
{
    [self callService:serviceId httpMethod:@"DELETE" httpHost:[self getHTTPHost] path:@"session" queryParameters:NULL messageBody:NULL application:[self getApplication] session:[BasicHttpService getSession]];
}

-(void) resetPassword: (NSString*) serviceId requestId:(NSString*) requestId newPassword:(NSString*) newPass
{
    NSMutableDictionary * query = [NSMutableDictionary dictionary];
    [query setObject:newPass forKey:@"new_password"];
    [query setObject:requestId forKey:@"request_id"];
    
    [self callService:serviceId httpMethod:@"POST" httpHost:[self getHTTPHost] path:@"account/password/reset" queryParameters:query messageBody:NULL application:[self getApplication] session:[BasicHttpService getSession]];
}

-(void) changePassword: (NSString*) serviceId oldPassword:(NSString*) oldPass newPassword:(NSString*) newPass
{
    NSMutableDictionary * query = [NSMutableDictionary dictionary];
    [query setObject:newPass forKey:@"new_password"];
    [query setObject:oldPass forKey:@"old_password"];
    
    [self callService:serviceId httpMethod:@"PUT" httpHost:[self getHTTPHost] path:@"account/password" queryParameters:query messageBody:NULL application:[self getApplication] session:[BasicHttpService getSession]];
}

-(void) getAccountInfo: (NSString*) serviceId ids:(NSString*) ids startTime:(int) startTime
{
    NSString* path;
    if (startTime>0) 
    {
          path = [NSString stringWithFormat:@"account?ids=%@&start_time=%l", ids, startTime];
    }
    else
    {
         path = [NSString stringWithFormat:@"account?ids=%@", ids];
    }
    [self callService:serviceId httpMethod:@"POST" httpHost:[self getHTTPHost] path:path queryParameters:NULL messageBody:NULL application:[self getApplication] session:[BasicHttpService getSession]];
}

-(void) create:(NSString*) serviceId providerName: (NSString*) providerName consumerKey:(NSString*) consumerKey consumerSecret:(NSString*) consumerSecret accessToken:(NSString*) accessToken requestToken:(NSString*) requestToken tokenSecret:(NSString*) tokenSecret protocalVersion:(NSString*) protocolVersion expirationTime:(NSString*) expirationTime
{
    NSMutableDictionary * query = [NSMutableDictionary dictionary];
    [query setObject:providerName forKey:@"provider_name"];
    [query setObject:consumerKey forKey:@"consumer_key"];

    [query setObject:consumerSecret forKey:@"consumer_secret"];
    [query setObject:accessToken forKey:@"access_token"];

    [query setObject:requestToken forKey:@"request_token"];
    [query setObject:tokenSecret forKey:@"token_secret"];

    [query setObject:protocolVersion forKey:@"protocol_version"];
    if(expirationTime) [query setObject:expirationTime forKey:@"expiration_time"];

    [self callService:serviceId httpMethod:@"POST" httpHost:[self getHTTPHost] path:@"account" queryParameters:query messageBody:NULL application:[self getApplication] session:NULL];
}

-(void) connect:(NSString*) serviceId providerName: (NSString*) providerName consumerKey:(NSString*) consumerKey consumerSecret:(NSString*) consumerSecret accessToken:(NSString*) accessToken requestToken:(NSString*) requestToken tokenSecret:(NSString*) tokenSecret protocalVersion:(NSString*) protocolVersion expirationTime:(NSString*) expirationTime
{
    NSMutableDictionary * query = [NSMutableDictionary dictionary];
    [query setObject:providerName forKey:@"provider_name"];
    [query setObject:consumerKey forKey:@"consumer_key"];
    
    [query setObject:consumerSecret forKey:@"consumer_secret"];
    [query setObject:accessToken forKey:@"access_token"];
    
    [query setObject:requestToken forKey:@"request_token"];
    [query setObject:tokenSecret forKey:@"token_secret"];

    [query setObject:protocolVersion forKey:@"protocol_version"];
    if(expirationTime) [query setObject:expirationTime forKey:@"expiration_time"];
    
    [self callService:serviceId httpMethod:@"POST" httpHost:[self getHTTPHost] path:@"session" queryParameters:query messageBody:NULL application:[self getApplication] session:NULL];
}
@end
